package lib.bone.nepudata.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lib.bone.access.validator.IsNepu;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "nepu_property")
@EntityListeners(AuditingEntityListener.class)
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
@ApiModel("知识产权记录")
public class NepuProperty {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "知识产权ID",name = "id")
    String id;


    /**
     * 知识产权编号
     */
    @ApiModelProperty(value = "知识产权编号")
    @Column(name = "property_code")
    String propertyCode;

    @ApiModelProperty("周期ID")
    @Column(name = "cycle_id")
    String cycleId;

    /**
     * 知识产权词典ID
     */
    @ApiModelProperty(value = "知识产权词典ID",notes = "")
    @Column(name = "property_dict_id")
    String propertyDictId;

    @ApiModelProperty(value = "知识产权名称")
    @Column(name = "property_name")
    String propertyName;



    /**
     * 第一完成人
     */
    @ApiModelProperty(value = "第一完成人")
    @Column(name = "first_author")
    String firstAuthor;

    /**
     * 第一完成人ID
     */
    @ApiModelProperty(value = "第一完成人ID")
    @Column(name = "first_author_id")
    Long firstAuthorId;

    /**
     * 第二完成人
     */
    @ApiModelProperty(value = "第二完成人")
    @Column(name = "second_author")
    String secondAuthor;

    /**
     * 第二完成人ID
     */
    @ApiModelProperty(value = "第二完成人ID")
    @Column(name = "second_author_id")
    Long secondAuthorId;


    /**
     * 第一署名单位
     */
    @IsNepu
    @ApiModelProperty(value = "第一署名单位")
    @Column(name = "first_signature_unit")
    String firstSignatureUnit;

    /**
     * 审核状态
     */
//    @ApiModelProperty("审核状态")
//    @Column(name = "status")
//    Integer status;

    /**
     * 分配所得工作量
     */
    @ApiModelProperty(value = "工作量",notes = "")
    @Column(name = "workload",scale = 2)
    Double workload;


    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NepuProperty nepuProperty = (NepuProperty) o;
        return id != null && Objects.equals(id, nepuProperty.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
